package com.yanqu.road.server.cmd.activity.zhenhuan.cross.thirdProcess;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.logic.activity.zhenhuan.ZhenHuanThirdProcessConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ZhenHuanProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityCivilRewardModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.server.manger.activity.zhenhuan.ZhenHuanConfigMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Cmd(code = Protocol.S_ZHENHUAN_THIRD_PROCESS_GET_ALL_USER_FROM_CROSS, desc = "跨服获取参赛者信息回包")
public class ZhenHuanThirdProcessGetAllUserFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ZhenHuanProto.ZhenHuanThirdProcessGetAllUserRespMsg reqMsg = ZhenHuanProto.ZhenHuanThirdProcessGetAllUserRespMsg.parseFrom(packet.getBytes());
        ZhenHuanProto.ZhenHuanThirdProcessGetAllUserRespMsg.Builder builder = reqMsg.toBuilder();
        List<ZhenHuanProto.ZhenHuanThirdProcessUserTempMsg.Builder> userDataList = new ArrayList<>();
        for (ZhenHuanProto.ZhenHuanThirdProcessUserTempMsg userData : builder.getUserListList()) {
            ZhenHuanProto.ZhenHuanThirdProcessUserTempMsg.Builder userBuilder = userData.toBuilder();
            //获取已领取的全民奖励condition id 集合
            Set<Integer> conditionIdSet = player.getModule(ActivityCivilRewardModule.class).getReceivedCivilRewardConditions(reqMsg.getActivityId(), userBuilder.getUserId());
            userBuilder.addAllReceivedCivilReward(conditionIdSet);
            userDataList.add(userBuilder);
        }
        builder.clearUserList();
        for (ZhenHuanProto.ZhenHuanThirdProcessUserTempMsg.Builder userData: userDataList) {
            builder.addUserList(userData);
        }
        player.sendPacket(Protocol.U_ZHENHUAN_THIRD_PROCESS_GET_ALL_USER, builder);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
